package com.neusoft.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neusoft.mapper.BooksMapperCustom;
import com.neusoft.mapper.base.BooksMapper;
import com.neusoft.mapper.base.UserMapper;
import com.neusoft.model.entity.Books;
import com.neusoft.model.entity.BooksExample;
import com.neusoft.model.entity.User;
import com.neusoft.model.entity.UserExample;
import com.neusoft.service.UserService;
@Service
public class UserServiceImpl implements UserService {

	@Autowired
	UserMapper userMapper;
	@Autowired
	BooksMapperCustom booksmapper;

	@Override
	public boolean testUser(String ID, String pwd) {
		
		List<User> userList = new ArrayList<User>();
		userList=findUserByIDAndPassword(ID, pwd);
		if (userList.size() != 0) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public List<User> findUserByIDAndPassword(String ID, String pwd) {
		UserExample ue = new UserExample();
		UserExample.Criteria uec = ue.createCriteria();
		uec.andIdEqualTo(ID);
		uec.andPasswordEqualTo(pwd);
		List<User> userList = new ArrayList<User>();
		userList = userMapper.selectByExample(ue);
		return userList;
	}

	/**
	 * TODO 主键冲突异常处理
	 */
	@Override
	public void insertUser(User user) {
		User daUser=userMapper.selectByPrimaryKey(user.getId());
		if(daUser==null){
		userMapper.insert(user);
		}
		
			return ;
	}

	@Override
	public List<Books> borrowing(String id) {
		BooksExample book = new BooksExample();
		BooksExample.Criteria find_book = book.createCriteria();
		find_book.andBorrowerEqualTo(id);
		
		List<Books> books = new ArrayList<Books>();
		books = booksmapper.selectByExample(book);
		System.out.println("1");
		
		return books;
	}



	
	

}
